

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="John Doe">
  <meta name="keywords" content="">
  
    <meta name="description" content="@[toc] 运行环境  windows10 IDEA专业版 JDK8 HTML5、CSS3、JavaScript JQuery Bootstrap5  1. 页面效果展示 1.1 登陆信息错误提示 1.2 文字验证码 1.3 用户查询自己发布的商品 2. 功能实现 2.1 文字验证码2.1.1 JSP页面代码123456789&lt;div class&#x3D;&quot;row&quot;&gt;	&amp;">
<meta property="og:type" content="article">
<meta property="og:title" content="Web项目实战 _ 购物系统v1.0 _ 开发记录（六）_使用coockie实现记住密码 _ 非登陆用户拦截 _ AJAX文字登陆验证 _ 使用Bootstrap5框架的模态框组件显示提示弹窗">
<meta property="og:url" content="http://example.com/2021/12/25/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E5%85%AD%EF%BC%89_%E4%BD%BF%E7%94%A8coockie%E5%AE%9E%E7%8E%B0%E8%AE%B0%E4%BD%8F%E5%AF%86%E7%A0%81%20_%20%E9%9D%9E%E7%99%BB%E9%99%86%E7%94%A8%E6%88%B7%E6%8B%A6%E6%88%AA%20_%20AJAX%E6%96%87%E5%AD%97%E7%99%BB%E9%99%86%E9%AA%8C%E8%AF%81%20_%20%E4%BD%BF%E7%94%A8Bootstrap5%E6%A1%86%E6%9E%B6%E7%9A%84%E6%A8%A1%E6%80%81%E6%A1%86%E7%BB%84%E4%BB%B6%E6%98%BE%E7%A4%BA%E6%8F%90%E7%A4%BA%E5%BC%B9%E7%AA%97/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="@[toc] 运行环境  windows10 IDEA专业版 JDK8 HTML5、CSS3、JavaScript JQuery Bootstrap5  1. 页面效果展示 1.1 登陆信息错误提示 1.2 文字验证码 1.3 用户查询自己发布的商品 2. 功能实现 2.1 文字验证码2.1.1 JSP页面代码123456789&lt;div class&#x3D;&quot;row&quot;&gt;	&amp;">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/8c158d18c1e14c6db35746eae136e510.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/814e58a6d9cd40319d070778d5980ac2.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/c7bf02515a7d45839993f5ea11e2b945.png#pic_center">
<meta property="og:image" content="https://img-blog.csdnimg.cn/8e3e5cdb009f45d8ae25082606073b4c.png#pic_center">
<meta property="article:published_time" content="2021-12-25T01:18:56.000Z">
<meta property="article:modified_time" content="2022-08-22T15:50:23.199Z">
<meta property="article:author" content="John Doe">
<meta property="article:tag" content="JavaWeb">
<meta property="article:tag" content="项目实战:购物系统v1.0">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/8c158d18c1e14c6db35746eae136e510.png#pic_center">
  
  
  
  <title>Web项目实战 _ 购物系统v1.0 _ 开发记录（六）_使用coockie实现记住密码 _ 非登陆用户拦截 _ AJAX文字登陆验证 _ 使用Bootstrap5框架的模态框组件显示提示弹窗 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>尤 Ni&#39;s Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Web项目实战 _ 购物系统v1.0 _ 开发记录（六）_使用coockie实现记住密码 _ 非登陆用户拦截 _ AJAX文字登陆验证 _ 使用Bootstrap5框架的模态框组件显示提示弹窗"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        John Doe
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2021-12-25 09:18" pubdate>
          2021年12月25日 上午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          7k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          59 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Web项目实战 _ 购物系统v1.0 _ 开发记录（六）_使用coockie实现记住密码 _ 非登陆用户拦截 _ AJAX文字登陆验证 _ 使用Bootstrap5框架的模态框组件显示提示弹窗</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：1 小时前
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <p>@[toc]</p>
<h1 id="运行环境"><a href="#运行环境" class="headerlink" title="运行环境"></a>运行环境</h1><hr>
<ul>
<li>windows10</li>
<li>IDEA专业版</li>
<li>JDK8</li>
<li>HTML5、CSS3、JavaScript</li>
<li>JQuery</li>
<li>Bootstrap5</li>
</ul>
<h1 id="1-页面效果展示"><a href="#1-页面效果展示" class="headerlink" title="1. 页面效果展示"></a>1. 页面效果展示</h1><hr>
<h2 id="1-1-登陆信息错误提示"><a href="#1-1-登陆信息错误提示" class="headerlink" title="1.1 登陆信息错误提示"></a>1.1 登陆信息错误提示</h2><p><img src="https://img-blog.csdnimg.cn/8c158d18c1e14c6db35746eae136e510.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"><br><img src="https://img-blog.csdnimg.cn/814e58a6d9cd40319d070778d5980ac2.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="1-2-文字验证码"><a href="#1-2-文字验证码" class="headerlink" title="1.2 文字验证码"></a>1.2 文字验证码</h2><p><img src="https://img-blog.csdnimg.cn/c7bf02515a7d45839993f5ea11e2b945.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h2 id="1-3-用户查询自己发布的商品"><a href="#1-3-用户查询自己发布的商品" class="headerlink" title="1.3 用户查询自己发布的商品"></a>1.3 用户查询自己发布的商品</h2><p><img src="https://img-blog.csdnimg.cn/8e3e5cdb009f45d8ae25082606073b4c.png#pic_center" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h1 id="2-功能实现"><a href="#2-功能实现" class="headerlink" title="2. 功能实现"></a>2. 功能实现</h1><hr>
<h2 id="2-1-文字验证码"><a href="#2-1-文字验证码" class="headerlink" title="2.1 文字验证码"></a>2.1 文字验证码</h2><h3 id="2-1-1-JSP页面代码"><a href="#2-1-1-JSP页面代码" class="headerlink" title="2.1.1 JSP页面代码"></a>2.1.1 JSP页面代码</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;row&quot;</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;ck&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-md-2 offset-md-1 fs-4&quot;</span>&gt;</span><br>		<span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">&quot;/code&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;list-style-type: none; color: black&quot;</span>&gt;</span>验证码<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><br>	<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;col-md-7 order-md-2&quot;</span>&gt;</span><br>		<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">id</span> = <span class="hljs-string">&quot;ck&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;ck&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;form-control w-100&quot;</span> <span class="hljs-attr">placeholder</span> = <span class="hljs-string">&quot;$&#123;sessionScope.problem&#125;&quot;</span>&gt;</span><br>	<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><br></code></pre></td></tr></table></figure>
<h3 id="2-1-2-Servlet类"><a href="#2-1-2-Servlet类" class="headerlink" title="2.1.2 Servlet类"></a>2.1.2 Servlet类</h3><p><code>CodeACtion.java</code></p>
<p>该类负责产生随机的两个100以内的数字，最后进行加法运算，将两个数字的相加作为问题字符串存入session域的problem对象，然后将相加的结果存入session域的answer对象，最终在前端页面直接判断即可。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.action;<br><br><span class="hljs-keyword">import</span> javax.servlet.ServletException;<br><span class="hljs-keyword">import</span> javax.servlet.annotation.WebServlet;<br><span class="hljs-keyword">import</span> javax.servlet.http.HttpServlet;<br><span class="hljs-keyword">import</span> javax.servlet.http.HttpServletRequest;<br><span class="hljs-keyword">import</span> javax.servlet.http.HttpServletResponse;<br><span class="hljs-keyword">import</span> javax.servlet.http.HttpSession;<br><span class="hljs-keyword">import</span> java.io.IOException;<br><span class="hljs-keyword">import</span> java.util.Random;<br><br><span class="hljs-meta">@WebServlet(name = &quot;CodeAction&quot;, urlPatterns = &quot;/code&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">CodeAction</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">HttpServlet</span> &#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">doGet</span><span class="hljs-params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="hljs-keyword">throws</span> ServletException, IOException &#123;<br>        <span class="hljs-type">int</span> <span class="hljs-variable">a</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Random</span>().nextInt(<span class="hljs-number">100</span>);<br>        <span class="hljs-type">int</span> <span class="hljs-variable">b</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Random</span>().nextInt(<span class="hljs-number">100</span>);<br>        <span class="hljs-type">int</span> <span class="hljs-variable">c</span> <span class="hljs-operator">=</span> a + b;<br>        <span class="hljs-type">HttpSession</span> <span class="hljs-variable">session</span> <span class="hljs-operator">=</span> req.getSession();<br>        session.setAttribute(<span class="hljs-string">&quot;problem&quot;</span>, a + <span class="hljs-string">&quot; + &quot;</span> +  b  + <span class="hljs-string">&quot; = &quot;</span> + <span class="hljs-string">&quot; ? &quot;</span>);<br>        session.setAttribute(<span class="hljs-string">&quot;answer&quot;</span>, c);<br>        resp.sendRedirect(<span class="hljs-string">&quot;login.jsp&quot;</span>);<br>    &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<h2 id="2-2-AJAX向后端发送请求实现记住密码"><a href="#2-2-AJAX向后端发送请求实现记住密码" class="headerlink" title="2.2 AJAX向后端发送请求实现记住密码"></a>2.2 AJAX向后端发送请求实现记住密码</h2><h3 id="2-2-1-JSP页面代码"><a href="#2-2-1-JSP页面代码" class="headerlink" title="2.2.1 JSP页面代码"></a>2.2.1 JSP页面代码</h3><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;re_user&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;checkbox&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;re_user&quot;</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;zoom: 180%&quot;</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">label</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;fs-4&quot;</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;re_user&quot;</span>&gt;</span>记住密码<span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h3 id="2-2-2-JS-JQuery-代码"><a href="#2-2-2-JS-JQuery-代码" class="headerlink" title="2.2.2 JS (JQuery) 代码"></a>2.2.2 JS (JQuery) 代码</h3><p>通过AJAX请求的方式，前端可以根据Servlet返回的结果进行判断，如果登陆失败则可以显示一个提示的弹窗，如果是直接将请求发送到Servlet不通过JS的AJAX，就无法判断是否成功登陆。</p>
<p>AJAX地址对应Servlet类里<code>urlPattern</code>的参数，由于笔者未用表单的提交而是直接将参数通过地址栏传入，故需要传入登陆信息的参数。</p>
<p>最终判断Servlet类向 <code>response</code> 对象写入的字符串，如果为 “ true “ 则表示登陆验证成功，最终则跳转到 <code>index.jsp</code> 。</p>
<p>这样的话，用户是不是能直接到 <code>index.jsp</code> 页面呢？</p>
<p>答案是不能，首先是首页有一些获取session域用户信息的代码，如果不存在可能会出现报错。</p>
<p>其次是后端会对这种情况进行处理，比如设置 Servlet 过滤器。</p>
<p>笔者的设定是登陆后才能访问首页，所以需要实现一个拦截非登录用户访问首页及其他登陆后才能访问的一些页面。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs javascript">$(<span class="hljs-variable language_">document</span>).<span class="hljs-title function_">ready</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br>   $(<span class="hljs-string">&quot;#login&quot;</span>).<span class="hljs-title function_">click</span>(<span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)&#123;<br>       <span class="hljs-keyword">var</span> username = $(<span class="hljs-string">&quot;#un&quot;</span>).<span class="hljs-title function_">val</span>();<br>       <span class="hljs-keyword">var</span> password = $(<span class="hljs-string">&quot;#pw&quot;</span>).<span class="hljs-title function_">val</span>();<br>       <span class="hljs-keyword">var</span> ck = $(<span class="hljs-string">&quot;#ck&quot;</span>).<span class="hljs-title function_">val</span>();<br>       $.<span class="hljs-title function_">ajax</span>(&#123;<br>          <span class="hljs-attr">type</span>: <span class="hljs-string">&#x27;POST&#x27;</span>,<br>          <span class="hljs-attr">url</span>: <span class="hljs-string">&quot;/toLogin?username=&quot;</span>+username + <span class="hljs-string">&quot;&amp;password=&quot;</span> + password+<span class="hljs-string">&quot;&amp;re=&quot;</span>+ $(<span class="hljs-string">&quot;#re_user&quot;</span>).<span class="hljs-title function_">prop</span>(<span class="hljs-string">&quot;checked&quot;</span>) + <span class="hljs-string">&quot;&amp;ck=&quot;</span> + ck,<br>          <span class="hljs-attr">async</span>: <span class="hljs-literal">false</span>,<br>          <span class="hljs-attr">error</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">data</span>) &#123;<br>              <span class="hljs-title function_">alert</span>(<span class="hljs-string">&#x27;操作失败&#x27;</span> + data);<br>          &#125;,<br>          <span class="hljs-attr">success</span>: <span class="hljs-keyword">function</span> (<span class="hljs-params">result</span>)&#123;<br>              <span class="hljs-keyword">if</span>(result != <span class="hljs-string">&quot;true&quot;</span>) &#123;<br>                  $(<span class="hljs-string">&quot;#modal-error-info&quot;</span>).<span class="hljs-title function_">html</span>(result);<br>                  $(<span class="hljs-string">&quot;#btn-modal-error&quot;</span>).<span class="hljs-title function_">click</span>();<br>              &#125;<br>              <span class="hljs-keyword">else</span> <span class="hljs-variable language_">window</span>.<span class="hljs-property">location</span>.<span class="hljs-property">href</span> = <span class="hljs-string">&quot;/index.jsp&quot;</span>;<br><br>          &#125;<br>      &#125;);<br>   &#125;);<br><br>&#125;);<br><br></code></pre></td></tr></table></figure>

<h3 id="2-2-3-错误提示模态框"><a href="#2-2-3-错误提示模态框" class="headerlink" title="2.2.3 错误提示模态框"></a>2.2.3 错误提示模态框</h3><p><a target="_blank" rel="noopener" href="https://v5.bootcss.com/docs/components/modal/">Bootstrap5 modal 官方文档</a></p>
<p>实现错误提示框的HTML代码</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;btn-modal-error&quot;</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;button&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn btn-success&quot;</span> <span class="hljs-attr">data-bs-toggle</span>=<span class="hljs-string">&quot;modal&quot;</span> <span class="hljs-attr">data-bs-target</span>=<span class="hljs-string">&quot;#modal-error&quot;</span> <span class="hljs-attr">hidden</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br><br><br><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal fade&quot;</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;modal-error&quot;</span> <span class="hljs-attr">tabindex</span>=<span class="hljs-string">&quot;-1&quot;</span> <span class="hljs-attr">aria-labelledby</span>=<span class="hljs-string">&quot;modal-error&quot;</span> <span class="hljs-attr">aria-hidden</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-dialog&quot;</span>&gt;</span><br>		<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-content&quot;</span>&gt;</span><br>			<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-header&quot;</span>&gt;</span><br>				<span class="hljs-tag">&lt;<span class="hljs-name">h5</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-title text-danger&quot;</span>&gt;</span><br>					<span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;bi bi-exclamation-triangle-fill&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span><br>					温馨提示<br>				<span class="hljs-tag">&lt;/<span class="hljs-name">h5</span>&gt;</span><br>				<span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;button&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn-close&quot;</span> <span class="hljs-attr">data-bs-dismiss</span>=<span class="hljs-string">&quot;modal&quot;</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">&quot;Close&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span><br>			<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>			<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;modal-body&quot;</span>&gt;</span><br>				<span class="hljs-tag">&lt;<span class="hljs-name">h5</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;text-warning text-center&quot;</span>&gt;</span><br>					<span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;bi bi-x-circle&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span><br>					<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">&quot;modal-error-info&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span><br>				<span class="hljs-tag">&lt;/<span class="hljs-name">h5</span>&gt;</span><br>			<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>		<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>	<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br></code></pre></td></tr></table></figure>

<p>模态框的显示，通过一个按钮，笔者这里设置的id是 <code>btn-modal-error</code> ，所以只要在JS代码中执行 </p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs javascript">$(<span class="hljs-string">&quot;#btn-modal-error&quot;</span>) <br></code></pre></td></tr></table></figure>
<p>而模态框的显示信息，则可以通过修改 模态框DIV里设置的一个ID为 <code>modal-error-info</code> 的 <code>span</code> 标签的值进行显示，综上，在JS代码中实现显示错误弹窗的提示代码如下：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><code class="hljs javascript">$(<span class="hljs-string">&quot;#modal-error-info&quot;</span>).<span class="hljs-title function_">val</span>(<span class="hljs-string">&quot;登陆失败&quot;</span>);<br>$(<span class="hljs-string">&quot;#btn-modal-error&quot;</span>).<span class="hljs-title function_">click</span>();<br></code></pre></td></tr></table></figure>

<h2 id="2-3-Coockie记住密码"><a href="#2-3-Coockie记住密码" class="headerlink" title="2.3 Coockie记住密码"></a>2.3 Coockie记住密码</h2><h3 id="2-3-1-关键JSP代码"><a href="#2-3-1-关键JSP代码" class="headerlink" title="2.3.1 关键JSP代码"></a>2.3.1 关键JSP代码</h3><p><code>login.jsp</code></p>
<p>在登陆页面中，账号密码输入框的内容可通过JSTL语句获取cookie域的对应username和password对象，直接显示之前保存的账号密码，若对象不存在则结果为空，不会影响页面显示。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs html">&lt;%@ taglib uri = &quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot;%&gt;<br><br><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span> <span class="hljs-attr">id</span> = <span class="hljs-string">&quot;un&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;username&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;form-control w-100 mb-4&quot;</span></span><br><span class="hljs-tag">							   <span class="hljs-attr">placeholder</span> = <span class="hljs-string">&quot;请输入用户名&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;$&#123;cookie.get(&quot;</span><span class="hljs-attr">username</span>&quot;)<span class="hljs-attr">.value</span>&#125;&quot;&gt;</span><br><br><span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;password&quot;</span> <span class="hljs-attr">id</span> = <span class="hljs-string">&quot;pw&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;password&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;form-control w-100 mb-4&quot;</span> <span class="hljs-attr">placeholder</span> = <span class="hljs-string">&quot;请输入密码&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;$&#123;cookie.get(&quot;</span><span class="hljs-attr">password</span>&quot;)<span class="hljs-attr">.value</span>&#125;&quot;&gt;</span><br></code></pre></td></tr></table></figure>

<h3 id="2-3-2-登陆验证的Servlet类"><a href="#2-3-2-登陆验证的Servlet类" class="headerlink" title="2.3.2 登陆验证的Servlet类"></a>2.3.2 登陆验证的Servlet类</h3><p><code>UserLoginAction.java</code></p>
<p>登陆验证除了验证用户名、密码、验证码正确性以外，还须判断是否记住密码，如果记住密码则需要向cookie域写入用户名和密码的值。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.uni.action;<br><br><span class="hljs-keyword">import</span> com.uni.entity.User;<br><span class="hljs-keyword">import</span> com.uni.service.Service;<br><br><span class="hljs-keyword">import</span> javax.servlet.ServletException;<br><span class="hljs-keyword">import</span> javax.servlet.annotation.WebServlet;<br><span class="hljs-keyword">import</span> javax.servlet.http.*;<br><span class="hljs-keyword">import</span> java.io.IOException;<br><br><span class="hljs-meta">@WebServlet(name = &quot;UserLoginServlet&quot;, urlPatterns = &quot;/toLogin&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">UserLoginAction</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">HttpServlet</span> &#123;<br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">doGet</span><span class="hljs-params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="hljs-keyword">throws</span> ServletException, IOException &#123;<br>        resp.getWriter().write(<span class="hljs-string">&quot;无法使用Get请求进行登陆&quot;</span>);<br>    &#125;<br><br>    <span class="hljs-meta">@Override</span><br>    <span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">doPost</span><span class="hljs-params">(HttpServletRequest req, HttpServletResponse resp)</span> <span class="hljs-keyword">throws</span> ServletException, IOException &#123;<br>        <span class="hljs-type">String</span> <span class="hljs-variable">username</span> <span class="hljs-operator">=</span> req.getParameter(<span class="hljs-string">&quot;username&quot;</span>);<br>        <span class="hljs-type">String</span> <span class="hljs-variable">password</span> <span class="hljs-operator">=</span> req.getParameter(<span class="hljs-string">&quot;password&quot;</span>);<br>        <span class="hljs-type">HttpSession</span> <span class="hljs-variable">session</span> <span class="hljs-operator">=</span> req.getSession();<br>        <span class="hljs-type">int</span> <span class="hljs-variable">ck</span> <span class="hljs-operator">=</span> Integer.parseInt(req.getParameter(<span class="hljs-string">&quot;ck&quot;</span>));<br>        <span class="hljs-type">Integer</span> <span class="hljs-variable">answer</span> <span class="hljs-operator">=</span> (Integer)session.getAttribute(<span class="hljs-string">&quot;answer&quot;</span>);<br>        <span class="hljs-type">boolean</span> <span class="hljs-variable">isRemember</span> <span class="hljs-operator">=</span> req.getParameter(<span class="hljs-string">&quot;re&quot;</span>).equals(<span class="hljs-string">&quot;true&quot;</span>);<br>        <span class="hljs-type">User</span> <span class="hljs-variable">user</span> <span class="hljs-operator">=</span> Service.user.checkUser(username, password);<br>        <span class="hljs-keyword">if</span>(user == <span class="hljs-literal">null</span>)&#123;<br>            resp.getWriter().write(<span class="hljs-string">&quot;账号密码有误&quot;</span>);<br>        &#125; <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span>(ck != answer)&#123;<br>            resp.getWriter().write(<span class="hljs-string">&quot;验证码错误&quot;</span>);<br>        &#125; <span class="hljs-keyword">else</span>&#123;<br><br>            <span class="hljs-comment">// 登录成功 就创建Cookie对象</span><br>            <span class="hljs-type">Cookie</span> <span class="hljs-variable">cname</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cookie</span>(<span class="hljs-string">&quot;username&quot;</span>, username);<br>            <span class="hljs-type">Cookie</span> <span class="hljs-variable">cpw</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Cookie</span>(<span class="hljs-string">&quot;password&quot;</span>, password);<br>            req.getSession().setAttribute(<span class="hljs-string">&quot;username&quot;</span>, username);<br>            <span class="hljs-keyword">if</span>(isRemember) &#123;<br>                <span class="hljs-comment">// 设置Cookie的有效时长 7天</span><br>                cname.setMaxAge(<span class="hljs-number">3600</span> * <span class="hljs-number">24</span> * <span class="hljs-number">7</span>);<br>                cpw.setMaxAge(<span class="hljs-number">3600</span> * <span class="hljs-number">24</span> * <span class="hljs-number">7</span>);<br>                <span class="hljs-comment">// 设置Cookie路径</span><br>                cname.setPath(req.getContextPath());<br>                cpw.setPath(req.getContextPath());<br>                <span class="hljs-comment">// 写入客户端</span><br>                resp.addCookie(cname);<br>                resp.addCookie(cpw);<br>            &#125;<br>            <span class="hljs-comment">/* 保存用户信息到 session域 */</span><br>            req.getSession().setAttribute(<span class="hljs-string">&quot;userInfo&quot;</span>, user);<br>            resp.getWriter().write(<span class="hljs-string">&quot;true&quot;</span>);<br>        &#125;<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<h1 id="3-总结"><a href="#3-总结" class="headerlink" title="3. 总结"></a>3. 总结</h1><hr>
<p>课设最后一天，终于完成了大部分功能，但还是有许多不足与BUG，这些都写在最后的总结里面吧，这一次的功能实现是基于web课程的实验，总体来说还是比较快的，可能更多的时间还是花在了样式的调整上，总体来说，之前下载的模板作用不太大，因为最终还是会按照自己的想法来设计的。</p>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1-0/" class="category-chain-item">项目实战:购物系统v1.0</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/JavaWeb/">#JavaWeb</a>
      
        <a href="/tags/%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98-%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1-0/">#项目实战:购物系统v1.0</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Web项目实战 _ 购物系统v1.0 _ 开发记录（六）_使用coockie实现记住密码 _ 非登陆用户拦截 _ AJAX文字登陆验证 _ 使用Bootstrap5框架的模态框组件显示提示弹窗</div>
      <div>http://example.com/2021/12/25/Web项目实战 _ 购物系统v1.0 _ 开发记录（六）_使用coockie实现记住密码 _ 非登陆用户拦截 _ AJAX文字登陆验证 _ 使用Bootstrap5框架的模态框组件显示提示弹窗/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>John Doe</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2021年12月25日</div>
        </div>
      
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/12/27/Python%20_%20%E4%B8%AD%E8%8B%B1%E6%96%87%E5%88%86%E8%AF%8Djieba%E6%A8%A1%E5%9D%97%20_%20%E8%AF%8D%E4%BA%91wordcloud%E6%A8%A1%E5%9D%97%20_%20%E5%BA%94%E7%94%A8Demo/" title="Python _ 中英文分词jieba模块 _ 词云wordcloud模块 _ 应用Demo">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Python _ 中英文分词jieba模块 _ 词云wordcloud模块 _ 应用Demo</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/12/24/Web%E9%A1%B9%E7%9B%AE%E5%AE%9E%E6%88%98%20_%20%E8%B4%AD%E7%89%A9%E7%B3%BB%E7%BB%9Fv1.0%20_%20%E5%BC%80%E5%8F%91%E8%AE%B0%E5%BD%95%EF%BC%88%E4%BA%94%EF%BC%89%20_%20%E6%A8%A1%E6%8B%9F%E7%BD%91%E7%AB%99%E5%9F%8B%E7%82%B9%E5%AE%9E%E7%8E%B0%E7%94%A8%E6%88%B7%E6%B5%8F%E8%A7%88%E8%AE%B0%E5%BD%95%E7%9A%84%E7%BB%9F%E8%AE%A1%E4%B8%8E%E6%98%BE%E7%A4%BA/" title="Web项目实战 _ 购物系统v1.0 _ 开发记录（五） _ 模拟网站埋点实现用户浏览记录的统计与显示">
                        <span class="hidden-mobile">Web项目实战 _ 购物系统v1.0 _ 开发记录（五） _ 模拟网站埋点实现用户浏览记录的统计与显示</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
